home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 24 / AACD 24.iso / AACD / Sound / LAME / WarpOS / src / mpglib / decode_i386.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-05  |  4.1 KB  |  180 lines

  1. /*
  2.  * Mpeg Layer-1,2,3 audio decoder
  3.  * ------------------------------
  4.  * copyright (c) 1995,1996,1997 by Michael Hipp, All rights reserved.
  5.  * See also 'README'
  6.  *
  7.  * slighlty optimized for machines without autoincrement/decrement.
  8.  * The performance is highly compiler dependend. Maybe
  9.  * the decode.c version for 'normal' processor may be faster
  10.  * even for Intel processors.
  11.  */
  12.  
  13. /* $Id: decode_i386.c,v 1.15 2001/01/15 15:16:09 aleidinger Exp $ */
  14.  
  15. #ifdef HAVE_CONFIG_H
  16. #include <config.h>
  17. #endif
  18.  
  19. #ifdef STDC_HEADERS
  20. # include <stdlib.h>
  21. # include <string.h>
  22. #else
  23. # ifndef HAVE_STRCHR
  24. #  define strchr index
  25. #  define strrchr rindex
  26. # endif
  27. char *strchr (), *strrchr ();
  28. # ifndef HAVE_MEMCPY
  29. #  define memcpy(d, s, n) bcopy ((s), (d), (n))
  30. #  define memmove(d, s, n) bcopy ((s), (d), (n))
  31. # endif
  32. #endif
  33.  
  34. #if defined(__riscos__) && defined(FPA10)
  35. #include    "ymath.h"
  36. #else
  37. #include    <math.h>
  38. #endif
  39.  
  40. #include "decode_i386.h"
  41. #include "dct64_i386.h"
  42. #include "tabinit.h"
  43.  
  44. #ifdef WITH_DMALLOC
  45. #include <dmalloc.h>
  46. #endif
  47.  
  48.  
  49.  /* old WRITE_SAMPLE */
  50. #define WRITE_SAMPLE(samples,sum,clip) \
  51.   if( (sum) > 32767.0) { *(samples) = 0x7fff; (clip)++; } \
  52.   else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \
  53.   else { *(samples) = ((sum)>0 ? (sum)+0.5 : (sum)-0.5) ; }
  54.  
  55. int synth_1to1_mono(PMPSTR mp, real *bandPtr,unsigned char *samples,int *pnt)
  56. {
  57.   short samples_tmp[64];
  58.   short *tmp1 = samples_tmp;
  59.   int i,ret;
  60.   int pnt1 = 0;
  61.  
  62.   ret = synth_1to1(mp,bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
  63.   samples += *pnt;
  64.  
  65.   for(i=0;i<32;i++) {
  66.     *( (short *) samples) = *tmp1;
  67.     samples += 2;
  68.     tmp1 += 2;
  69.   }
  70.   *pnt += 64;
  71.  
  72.   return ret;
  73. }
  74.  
  75. int synth_1to1(PMPSTR mp, real *bandPtr,int channel,unsigned char *out,int *pnt)
  76. {
  77.   static const int step = 2;
  78.   int bo;
  79.   short *samples = (short *) (out + *pnt);
  80.  
  81.   real *b0,(*buf)[0x110];
  82.   int clip = 0;
  83.   int bo1;
  84.  
  85.   bo = mp->synth_bo;
  86.  
  87.   if(!channel) {
  88.     bo--;
  89.     bo &= 0xf;
  90.     buf = mp->synth_buffs[0];
  91.   }
  92.   else {
  93.     samples++;
  94.     buf = mp->synth_buffs[1];
  95.   }
  96.  
  97.   if(bo & 0x1) {
  98.     b0 = buf[0];
  99.     bo1 = bo;
  100.     dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr);
  101.   }
  102.   else {
  103.     b0 = buf[1];
  104.     bo1 = bo+1;
  105.     dct64(buf[0]+bo,buf[1]+bo+1,bandPtr);
  106.   }
  107.  
  108.   mp->synth_bo = bo;
  109.  
  110.   {
  111.     register int j;
  112.     real *window = decwin + 16 - bo1;
  113.  
  114.     for (j=16;j;j--,b0+=0x10,window+=0x20,samples+=step)
  115.     {
  116.       real sum;
  117.       sum  = window[0x0] * b0[0x0];
  118.       sum -= window[0x1] * b0[0x1];
  119.       sum += window[0x2] * b0[0x2];
  120.       sum -= window[0x3] * b0[0x3];
  121.       sum += window[0x4] * b0[0x4];
  122.       sum -= window[0x5] * b0[0x5];
  123.       sum += window[0x6] * b0[0x6];
  124.       sum -= window[0x7] * b0[0x7];
  125.       sum += window[0x8] * b0[0x8];
  126.       sum -= window[0x9] * b0[0x9];
  127.       sum += window[0xA] * b0[0xA];
  128.       sum -= window[0xB] * b0[0xB];
  129.       sum += window[0xC] * b0[0xC];
  130.       sum -= window[0xD] * b0[0xD];
  131.       sum += window[0xE] * b0[0xE];
  132.       sum -= window[0xF] * b0[0xF];
  133.  
  134.       WRITE_SAMPLE(samples,sum,clip);
  135.     }
  136.  
  137.     {
  138.       real sum;
  139.       sum  = window[0x0] * b0[0x0];
  140.       sum += window[0x2] * b0[0x2];
  141.       sum += window[0x4] * b0[0x4];
  142.       sum += window[0x6] * b0[0x6];
  143.       sum += window[0x8] * b0[0x8];
  144.       sum += window[0xA] * b0[0xA];
  145.       sum += window[0xC] * b0[0xC];
  146.       sum += window[0xE] * b0[0xE];
  147.       WRITE_SAMPLE(samples,sum,clip);
  148.       b0-=0x10,window-=0x20,samples+=step;
  149.     }
  150.     window += bo1<<1;
  151.  
  152.     for (j=15;j;j--,b0-=0x10,window-=0x20,samples+=step)
  153.     {
  154.       real sum;
  155.       sum = -window[-0x1] * b0[0x0];
  156.       sum -= window[-0x2] * b0[0x1];
  157.       sum -= window[-0x3] * b0[0x2];
  158.       sum -= window[-0x4] * b0[0x3];
  159.       sum -= window[-0x5] * b0[0x4];
  160.       sum -= window[-0x6] * b0[0x5];
  161.       sum -= window[-0x7] * b0[0x6];
  162.       sum -= window[-0x8] * b0[0x7];
  163.       sum -= window[-0x9] * b0[0x8];
  164.       sum -= window[-0xA] * b0[0x9];
  165.       sum -= window[-0xB] * b0[0xA];
  166.       sum -= window[-0xC] * b0[0xB];
  167.       sum -= window[-0xD] * b0[0xC];
  168.       sum -= window[-0xE] * b0[0xD];
  169.       sum -= window[-0xF] * b0[0xE];
  170.       sum -= window[-0x0] * b0[0xF];
  171.  
  172.       WRITE_SAMPLE(samples,sum,clip);
  173.     }
  174.   }
  175.   *pnt += 128;
  176.  
  177.   return clip;
  178. }
  179.  
  180.